package name.flurl.android.tt_news4android;

import java.util.ArrayList;
import java.util.Arrays;

import android.app.Application;
import android.content.Context;
import android.preference.PreferenceManager;
import android.util.Log;
import android.view.Display;
import android.view.WindowManager;

public class Tt_news4AndroidApplication extends Application {

	public final static class CONSTANTS {
		public final static int DIRECTION_NEXT = 0;
		public final static int DIRECTION_PREVIOUS = 1;

		public final static int FORTHCOMMING = 100;
		public final static int PREVIOUS = 101;

		public static final int MSG_LOADING = 200;
		public static final int MSG_LOADING_FINISHED = 201;
		public static final int MSG_EOF = 202;

		public static final int LOADINGDLG = 220;

		public static final int SWIPE_MIN_DISTANCE = 120;
		public static final int SWIPE_MAX_OFF_PATH = 250;
		public static final int SWIPE_THRESHOLD_VELOCITY = 200;

		public final static String LATESTGALLERYURL = "http://www.postgarage.at/api/events.php?what=LATESTGAL";
		public static final int DEF_SLIDE_DURATION = 500;

		public static final String[][] PREDEFINED_SITES = {
				{ "Test 1",
						"http://10.0.2.2/tt_news4android/index.php?id=2&type=1264" },
				{ "Test 2",
						"http://10.0.2.2/tt_news4android/index.php?id=4&type=1264" } };
		// public static final String[][] PREDEFINED_SITES = {};

	}

	public int getDisplayHeight() {
		Display display = ((WindowManager) getSystemService(Context.WINDOW_SERVICE))
				.getDefaultDisplay();
		int height = display.getHeight();
		return height;
	}

	public int getDisplayWidth() {
		Display display = ((WindowManager) getSystemService(Context.WINDOW_SERVICE))
				.getDefaultDisplay();
		int width = display.getWidth();
		return width;
	}

	public int getDisplayOrientation() {
		Display display = ((WindowManager) getSystemService(Context.WINDOW_SERVICE))
				.getDefaultDisplay();
		int orientation = display.getOrientation();
		return orientation;
	}

	// returns configured sites, if defined as constant return constant, else
	// return from preferences
	public ArrayList<String[]> getSites() {
		if (CONSTANTS.PREDEFINED_SITES.length != 0) {
			Log.i("tt_news", "predefined sites");
			return new ArrayList<String[]>(Arrays
					.asList(CONSTANTS.PREDEFINED_SITES));
		} else {
			Log.i("tt_news", "preference sites");
			Tt_news4AndroidSharedPreferences preferences = new Tt_news4AndroidSharedPreferences(
					PreferenceManager.getDefaultSharedPreferences(this));
			return preferences.getSites("siteUrlsPref");
		}
	}
}
